$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'TeacherEvaluationSum/Select',
        datatype: "json",
        colModel: [
            { label: '日期', name: 'evaluationTime', width: 40,key: true },
             { label: '教师姓名', name: 'teacherName', index:'teacher_name',width: 35 },
            { label: '工号', name: 'teacherId', index:'teacher_name',width: 45 },
            { label: '所属院系', name: 'teacherCollege',index:'teacher_college', width: 45 },
            { label: '课程名称', name: 'courseId', index:'teacher_name',width: 50 },
            { label: '授课班级', name: 'className',index:'operator_name', width: 60 },
            { label: '学生姓名', name: 'studentName',index:'operator_name', width: 40 },
            { label: '学号', name: 'studentSchoolId',index:'operator_name', width: 45 },
            { label: '教学态度', name: 'teachingAttitude', width: 35 },
            { label: '教学效果', name: 'teachingEffectiveness', width: 35 },
            { label: '教学内容', name: 'teachingContent', width: 35 },
            { label: '教学环节', name: 'teachingLink', width: 35 },
            { label: '操作', name: 'caozuo', width: 50, formatter: function(value, options, row){
                    var evaluationTime=row.evaluationTime;
                    var teacherId=row.teacherId;
                    var courseId=row.courseId;
                    var studentSchoolId=row.studentSchoolId;
                    var teacherName=row.teacherName;
                    var studentName=row.studentName;
                var r=
                    '&nbsp;&nbsp;<a class="detail-btn" onclick="getDetails(\''+evaluationTime+'\',\''+teacherName+'\',\''+teacherId+'\',\''+courseId+'\',\''+studentSchoolId+'\',\''+studentName+'\')">详情</a>'

                return r;
                // '             <a class="btn btn-primary"><i class="fa fa-trash-o"></i>&nbsp;删除</a>';
            }}

        ],
        viewrecords: true,
        height:'100%',
        rowNum: 10,
        rowList : [10,30,50],
        // rownumbers: true,
        // rownumWidth: 25,
        autowidth:true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "scroll" });
        },
        ondblClickRow:function(rowid){
        }
    });
    $("#exportExcel").attr('href',baseURL+'TeacherEvaluationSum/export?token='+token);

});
function  getDetails(evaluationTime,teacherName,teacherId,courseId,studentSchoolId,studentName) {
    vm.showList = false;
    $.ajax({
        type: "POST",
        url: baseURL + "TeacherEvaluationSum/getTeacherEvaluationEntity",
        data:
            {
                evaluationTime:evaluationTime,
                courseId:courseId,
                teacherId:teacherId,
                studentSchoolId:studentSchoolId
            },
        success: function(r){
            if(r.code == 0){
                vm.title ='教师姓名：'+ teacherName+'   ' +
                    '  工号：'+teacherId+'  ' +
                    '  课程：'+courseId+"   " +
                    '  学生姓名：'+studentName+"   " +
                    "  学号："+studentSchoolId;
                vm.teacherEvaluationEntity=r.page;
            }else{
                alert(r.msg);
            }
        }
    });
}
var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            key: null
        },
        showList: true,
        title: null,
        TeacherEvaluationSum: {},
        date: null,
        teacherEvaluationEntity:null
    },
    methods: {
        query: function () {
            $("#exportExcel").attr('href',baseURL+'TeacherEvaluationSum/export?token='+token+"&teacherName="+vm.q.key);
            vm.reload();
        },
        add: function(){
            vm.showList = false;
            vm.title = "新增";
            vm.TeacherEvaluationSum = {};
        },
        update: function () {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            $.get(baseURL + "TeacherEvaluationSum/Info/"+id, function(r){
                vm.showList = false;
                vm.title = "修改";
                vm.TeacherEvaluationSum = r.TeacherEvaluationSum;
                vm.date = r.TeacherEvaluationSum.date;
            });
        },
        del: function () {
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "TeacherEvaluationSum/Delete",
                    contentType: "application/json",
                    data: JSON.stringify(ids),
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },
        typeColor(val){
            var bgClass=''
            if(val=='优'){
                bgClass='excellent'
            }else if(val=='良'){
                bgClass='secondary'
            }else if(val=='差'){
                bgClass='bad'
            }
            return bgClass
        },
        saveOrUpdate: function () {
            if(vm.validator()){
                return ;
            }

            var url = vm.TeacherEvaluationSum.date == vm.date ? "TeacherEvaluationSum/Update" : "TeacherEvaluationSum/Insert";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.TeacherEvaluationSum),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{ 'teacherName': vm.q.key},
                page:page
            }).trigger("reloadGrid");
        },
        validator: function () {
            if(isBlank(vm.TeacherEvaluationSum.date)){
                alert("日期不能为空");
                return true;
            }
            if(isBlank(vm.TeacherEvaluationSum.teacherCollege)){
                alert("所属学院不能为空");
                return true;
            }
            if(isBlank(vm.TeacherEvaluationSum.teacherName)){
                alert("教师姓名不能为空");
                return true;
            }
            if(isBlank(vm.TeacherEvaluationSum.excellent)){
                alert("优不能为空");
                return true;
            }
            if(isBlank(vm.TeacherEvaluationSum.good)){
                alert("良不能为空");
                return true;
            }
            if(isBlank(vm.TeacherEvaluationSum.poor)){
                alert("差不能为空");
                return true;
            }
            }
        }
});